<?php

namespace api\modules\app\controllers;

use api\components\BaseController;
use api\modules\app\services\EventService;
use api\traits\ControllerTrait;
use app\components\PaidanService;

class EventController extends BaseController
{

    use ControllerTrait;
    public $modelClass = 'api\\modules\\app\\models\\UnitEvent';

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['create'], $actions['index']);

        return $actions;
    }

    public function actionIndex() {
        $query = $this->getQuery();
        $service = new EventService();
        $data = $service->search($query);
        $count =  $service->search($query, true);

        return [
            'count' => $count,
            'data' => $data,
        ];
    }

    public function actionExport() {
        $query = $this->getQuery();
        $service = new EventService();
        return $service->export($query);
    }

    public function actionInfo() {
        $eventId = $this->getQuery('event_id', '');
        if (empty($eventId)) {
            return [];
        }
        $service = new PaidanService();
        return $service->getEventInfo($eventId);
    }

}